﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Masterpages/Main.master" AutoEventWireup="true" CodeFile="ExcelOutputMultiSelectPage1.aspx.cs" Inherits="User_Shares_ExcelOutputSelectPage" %>

<%@ Register src="../../Controls/ContentHolder/Holder1.ascx" tagname="Holder1" tagprefix="uc1" %>

<asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server">
 <script type="text/javascript">
     var TotalChkBx;
     var Counter;

     window.onload = function () {
         //Get total no. of CheckBoxes in side the GridView.
         TotalChkBx = parseInt('<%= this.GridViewProjects.Rows.Count %>');

         //Get total no. of checked CheckBoxes in side the GridView.
         Counter = 0;
     }

     function HeaderClick(CheckBox) {
         //Get target base & child control.
         var TargetBaseControl =
       document.getElementById('<%= this.GridViewProjects.ClientID %>');
         var TargetChildControl = "CheckBoxItemSelect";

         //Get all the control of the type INPUT in the base control.
         var Inputs = TargetBaseControl.getElementsByTagName("input");

         //Checked/Unchecked all the checkBoxes in side the GridView.
         for (var n = 0; n < Inputs.length; ++n)
             if (Inputs[n].type == 'checkbox' &&
                Inputs[n].id.indexOf(TargetChildControl, 0) >= 0)
                 Inputs[n].checked = CheckBox.checked;

         //Reset Counter
         Counter = CheckBox.checked ? TotalChkBx : 0;
     }

     function ChildClick(CheckBox, HCheckBox) {
         //get target control.
         var HeaderCheckBox = document.getElementById(HCheckBox);

         //Modifiy Counter; 
         if (CheckBox.checked && Counter < TotalChkBx)
             Counter++;
         else if (Counter > 0)
             Counter--;

         //Change state of the header CheckBox.
         if (Counter < TotalChkBx)
             HeaderCheckBox.checked = false;
         else if (Counter == TotalChkBx)
             HeaderCheckBox.checked = true;
     }
</script>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">

    <asp:UpdatePanel ID="UpdatePanel1" runat="server">
        <ContentTemplate>
            <asp:LoginView ID="LoginViewSearch" runat="server">
                <RoleGroups>
                    <asp:RoleGroup Roles="admin,bonyadshahrestan,fourthfactor,employer,edituser,viewuser">
                        <ContentTemplate>
                        <div id="adminToolsContainer" style="background-color:#CCCCFF;">
                            <div class="append-7" style="background-color: #CCCCFF; margin: 5px auto; direction: rtl; text-align:right;">
                                <asp:RadioButton ID="CheckBoxAdvisor" runat="server" Text="مشاوران" Checked="true" OnCheckedChanged="CheckBox_CheckedChanged" AutoPostBack="True" GroupName="category" />
                                <asp:RadioButton ID="CheckBoxSurveyor" runat="server" Text="نقشه برداران"  GroupName="category"
                                    OnCheckedChanged="CheckBox_CheckedChanged" AutoPostBack="True" />
                            </div>
                            <br />
                                          <div id="sort">
                  <asp:DropDownList ID="DropDownListSort" runat="server" AutoPostBack="true" OnSelectedIndexChanged="DropDownChanged">
                  <asp:ListItem Selected="True" Text="روستا" Value="0"></asp:ListItem>
                  <asp:ListItem  Text="نام مشاور یا نقشه بردار" Value="1"></asp:ListItem>
                  <asp:ListItem Text="شماره قرارداد" Value="2"></asp:ListItem>
                  <asp:ListItem Text="شهرستان" Value="3"></asp:ListItem>
                  </asp:DropDownList>
                  <br />
                  <asp:RadioButton ID="RadioButtonAsc" runat="server" Text="افزایشی"  GroupName="sort" AutoPostBack="True" Checked="true" OnCheckedChanged="RadioButton_CheckedChanged"/>
                  <br />
                  <asp:RadioButton ID="RadioButtonDec" runat="server" Text="کاهشی" GroupName="sort" AutoPostBack="True" OnCheckedChanged="RadioButton_CheckedChanged" />
                  </div>
                  <div id="resultCount">
                      <asp:Label ID="Label2" runat="server" Text="تعداد خروجی قابل نمایش:"></asp:Label>
                      <asp:DropDownList ID="DropDownListCount" runat="server" Width="40" AutoPostBack="True" OnSelectedIndexChanged="DropDownChanged">
                      <asp:ListItem Text="10" Value="10" Selected="True"></asp:ListItem>
                      <asp:ListItem Text="20" Value="20"></asp:ListItem>
                      <asp:ListItem Text="50" Value="50"></asp:ListItem>
                      <asp:ListItem Text="100" Value="100"></asp:ListItem>
                      </asp:DropDownList>
                  </div>
                  </div>
                        </ContentTemplate>
                    </asp:RoleGroup>
                    <asp:RoleGroup Roles="Surveyor,advisor">
                    </asp:RoleGroup>
                </RoleGroups>
            </asp:LoginView>
            <br />
            <div style="margin: 0px 20px;">
                
                <uc1:Holder1 ID="Holder11" runat="server" Title="لیست پروژه ها">
                <ContentTemplate>
                                <asp:Label ID="Label1" runat="server" Text="پروژه های مورد نظر برای گرفتن خروجی را انتخاب نمایید و در انتها دکمه پایین صفحه را بزنید."></asp:Label>
                                <br />

                <asp:GridView ID="GridViewProjects" runat="server"  AutoGenerateColumns="False"
                    EnableModelValidation="True" AllowPaging="True" AllowSorting="True"
                    BackColor="#CCCCFF" OnPreRender="GridViewProjects_PreRender" 
                    OnRowDataBound="GridViewProjects_RowDataBound" DataKeyNames="ContractId" 
                    PageSize="30" onrowcreated="GridViewProjects_RowCreated" RowStyle-Width="100">
                    <AlternatingRowStyle BackColor="#688CF5" />
                    <Columns>
                        <asp:BoundField DataField="AdvisorFullName" HeaderText="نام مشاور" ItemStyle-Wrap="true" ItemStyle-Width="120" />
                        <asp:BoundField DataField="ContractDate" HeaderText="تاریخ قرارداد" />
                        <asp:BoundField DataField="ContractNumber" HeaderText="شماره قرارداد" />
                        <asp:BoundField DataField="ContractTypeText" HeaderText="نوع  قرارداد" />
                        <asp:BoundField DataField="ContractYear" HeaderText="سال"  ItemStyle-Font-Bold="true"/>
                        <asp:BoundField DataField="City" HeaderText="نام شهرستان" />
                        <asp:BoundField DataField="Bakhsh" HeaderText="نام بخش" />                        
                        <asp:BoundField DataField="Dehestan" HeaderText="نام دهستان" />
                        <asp:BoundField DataField="VillageName" HeaderText="نام روستا" />
                        <asp:TemplateField HeaderText="دیرکرد">
                            <ItemTemplate>
                                <asp:Label ID="LabelDelay" runat="server" Text='<%# Eval("Delay") + " روز"  %>'></asp:Label>
                            </ItemTemplate>
                        </asp:TemplateField>
                        <asp:TemplateField HeaderText="انتخاب">
                            <HeaderTemplate>
                                <asp:CheckBox ID="CheckBoxSelectAll" AutoPostBack="true" runat="server" onclick="javascript:HeaderClick(this);" Checked="False" />
                            </HeaderTemplate>
                            <ItemTemplate>
                                <asp:CheckBox ID="CheckBoxItemSelect" runat="server" AutoPostBack="True" 
                                    oncheckedchanged="CheckBoxItemSelect_CheckedChanged" />
                            </ItemTemplate>

                        </asp:TemplateField>
                    </Columns>
                    <HeaderStyle BackColor="#688CF5" ForeColor="#000066" />                    
                    <PagerStyle BackColor="#688CF5" />
                    <PagerTemplate>
                        <div class="append-11 footer">
                            <asp:UpdatePanel ID="UpdatePanelFooter" runat="server">
                                <ContentTemplate>
                                    <table cellpadding="3">
                                        <tr>
                                            <td>
                                                <asp:LinkButton ID="LinkButtonLast" runat="server" OnClick="LinkButtonLast_Click">آخرین</asp:LinkButton>
                                            </td>
                                            <td>
                                                <asp:LinkButton ID="LinkButtonNext" runat="server" OnClick="LinkButtonNext_Click">بعدی</asp:LinkButton>
                                            </td>
                                            <td>
                                                <asp:LinkButton ID="LinkButtonPrevious" runat="server" OnClick="LinkButtonPrevious_Click">قبلی</asp:LinkButton>
                                            </td>
                                            <td>
                                                <asp:LinkButton ID="LinkButtonFirst" runat="server" OnClick="LinkButtonFirst_Click">اولین</asp:LinkButton>
                                            </td>
                                        </tr>
                                    </table>
                                    <br />
                                    <asp:Label ID="LabelPageNumber" runat="server" Text=""></asp:Label>
                                </ContentTemplate>
                            </asp:UpdatePanel>
                        </div>
                    </PagerTemplate>
                    
                </asp:GridView>
                <br />
                <asp:Button ID="ButtonExcel" runat="server" Text="رفتن به صفحه خروجی" 
                    onclick="ButtonExcel_Click" />
                </ContentTemplate>
                </uc1:Holder1>

            </div>
        </ContentTemplate>
        <Triggers>
            <asp:AsyncPostBackTrigger ControlID="LoginViewSearch" />            
        </Triggers>
    </asp:UpdatePanel>
</asp:Content>

